package com.cloud.bssp.java8.lambda;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;

/**
 * @description： TODO
 * @author：weirx
 * @date：2021/10/19 13:57
 * @version：3.0
 */
public class TestFunction {

    public static <T, R> List<R> map(List<T> list, Function<T, R> function) {
        List<R> results = new ArrayList<>();
        for (T t : list) {
            results.add(function.apply(t));
        }
        return results;
    }

    public static void main(String[] args) {
        List<Integer> map = map(Arrays.asList("Tom", "Jerry", "XiaoMing"), (String s) -> s.length());
        System.out.println(map);
    }
}
